USE Liberty
GO
-- ------------------------------------------------------------------------------------------------
-- Events create table script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Events table...'
GO

IF OBJECT_ID( 'Events' ) IS NULL
BEGIN
    CREATE TABLE dbo.Events 
	(OID				bigint		IDENTITY(1, 1)	NOT NULL
	,Version			rowversion
	,ActivityID			bigint						NOT NULL 
	,UserID				bigint						NOT NULL 
	,EventTime			datetime					NOT NULL
		CONSTRAINT DFLT_Events_EventTime DEFAULT GETDATE()

	,CONSTRAINT PK_Events PRIMARY KEY CLUSTERED (OID)

	,CONSTRAINT FK_Events_TypeOfActivity FOREIGN KEY (ActivityID) 
		REFERENCES DBO.TypesOfActivity(OID)

	,CONSTRAINT FK_Events_Users FOREIGN KEY (UserID)
		REFERENCES DBO.Users(OID)

	)
	PRINT 'Events table has been created...'
END
ELSE
BEGIN
	PRINT 'Events table already exists'
END
GO

